<?php
namespace app\gr\controller;

use app\common\wechat\Wxauth;
use app\gr\BLL\CardRedeemBLL;
use cmf\controller\HomeBaseController;

class CardRedeemController extends HomeBaseController
{
    private $bll;
    private $ControlName = "CardRedeem";

    public function __construct(CardRedeemBLL $cardRedeem)
    {
        parent::__construct();
        $this->bll = $cardRedeem;
    }

    public function index()
    {
        //获取openid
        if (config('is_server')) {
            $auth = new Wxauth(config('wechat'), 'base');
            $openid = $auth->openid;
        } else {
            $openid = "a123458";
        }
        $where['a.openid'] = $openid;
        $list = $this->bll->getList($where);
        $this->assign('list', $list);
        return $this->fetch();
    }

    public function show()
    {
        $id = input('id');
        //获取基本信息
        $columns = 'type.img,type.name tpname,type.spk,a.*';

        $info = $this->bll->getbyid($id, $columns);
        // var_dump($info);die;
        $status = $info['express_status'];
        $com = $info['express_type'];
        $num = $info['express_no'];
        $tele = $info['tele'];
        $expressData = array();
        if ($status) {
            //查询快递信息
            $express = express($com, $num, $tele);
            if (array_key_exists('data', $express)) {
                $expressData = $express['data'];
            }

        }
        // var_dump($express);die;
        $this->assign('info', $info);
        $this->assign('express', $expressData);
        return $this->fetch();

    }
}
